package cn.iocoder.yudao.module.system.controller.admin.ai;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.lottery.vo.LotteryRespVO;
import cn.iocoder.yudao.module.system.controller.admin.lottery.vo.LotteryRecordRespVO;
import cn.iocoder.yudao.module.system.service.lottery.LotteryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * @author zhaoying
 */
@Tag(name = "管理后台 - 首页")
@RestController
@RequestMapping("/system/index")
@Validated
@Slf4j
public class IndexController {

    @Resource
    private LotteryService lotteryService;

    @PostMapping("/lottery/draw")
    @Operation(summary = "用户抽奖")
    @PermitAll
    public CommonResult<LotteryRespVO> drawLottery() {
        Long userId = getLoginUserId();
        return success(lotteryService.drawLottery(userId));
    }

    @GetMapping("/lottery/records")
    @Operation(summary = "获取用户抽奖记录")
    @PermitAll
    public CommonResult<List<LotteryRecordRespVO>> getUserLotteryRecords() {
        Long userId = getLoginUserId();
        return success(lotteryService.getUserLotteryRecords(userId));
    }

    @GetMapping("/lottery/can-draw")
    @Operation(summary = "检查用户是否还能抽奖")
    @PermitAll
    public CommonResult<Boolean> canDrawLottery() {
        Long userId = getLoginUserId();
        return success(lotteryService.canDrawLottery(userId));
    }

    @GetMapping("/lottery/remaining-count")
    @Operation(summary = "获取用户今日剩余抽奖次数")
    @PermitAll
    public CommonResult<Integer> getRemainingLotteryCount() {
        Long userId = getLoginUserId();
        return success(lotteryService.getRemainingLotteryCount(userId));
    }

    @GetMapping("/lottery/full-package-info")
    @Operation(summary = "获取全套奖励详情")
    @PermitAll
    public CommonResult<String> getFullPackageInfo() {
        // 检查专业版报告库存状态
        boolean hasProfessionalReportStock = true; // 这里可以调用检查库存的方法
        return success(lotteryService.getFullPackageDescription(hasProfessionalReportStock));
    }
}
